import os
import shutil
import re

# List of folder and corresponding simulation parameters
percentage_list =[0.0,0.01,0.02,0.05,0.1];
W = 0.1;
folder_list=[];
while W < 2.01:
    for percentage in percentage_list:
        folder = 'W_'+str(W)+'_A_'+str(percentage*W)
        folder_list.append((folder,W,W*percentage))
    W = W+0.1
print str(folder_list)

repeat = 1
bin = "~/LPCVD/Simulations3/Open_loop/Controller_10/simulation.out"

# Constants that are not changed in this set of simulations
print "making the following folder(s) "
for i in range(len(folder_list)):
    folder=folder_list[i][0]
    W=folder_list[i][1]
    A=folder_list[i][2]
    print i, folder
    if os.path.exists(folder):
        pass
    else:
        os.mkdir(folder)
#    shutil.copy('./simulation.template',folder+'/simulation.sh')
    p_folder = re.compile('VAL_CUR_FOLDER')
    p_W = re.compile('VAL_W')
    p_A = re.compile('VAL_A')
    p_repeat = re.compile('VAL_REPEAT')
    if 'nt'==os.name:
        fi = open('./simulation.template.bat')
        fo = open(folder+'/simulation.bat','w')
    else:
        fi = open('./simulation.template.sh')
        fo = open(folder+'/simulation.sh','w')
    for line in fi:
        line = p_folder.sub(folder,line)
        line = p_W.sub(str(W),line)
        line = p_A.sub(str(A),line)
        line = p_repeat.sub(str(repeat),line)
        fo.write(line)
    fi.close()
    fo.close()
    # Submit jobs using qsub
    if 'posix'==os.name:
        print "Ready for qsub\n"
        # Uncomment the following line when you are satisfied with the generated script files
#        os.system('qsub -v LD_LIBRARY_PATH -l h_rt=12:00:00 '+folder+'/simulation.sh')



 
    
        
    
    

    

